package com.tao.aszx.manager.controller;

import com.tao.aszx.manager.service.SysMenuService;
import com.tao.aszx.model.entity.system.SysMenu;
import com.tao.aszx.model.vo.common.Result;
import com.tao.aszx.model.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Resource
    SysMenuService sysMenuService;

    @PostMapping("/save")
    public Result saveSysMenu(@RequestBody SysMenu sysMenu){
        int num = sysMenuService.saveMenu(sysMenu);
        if(!(num > 0)){
            return Result.build(null,218,"菜单已存在");
        }
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findNodes")
    public Result findSysMenus(){
        //查询
        List<SysMenu> sysMenus =  sysMenuService.findSysMenus();

        return Result.build(sysMenus, ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateById(sysMenu);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable Long id) {
        sysMenuService.removeById(id);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }



}
